filter_var_array
Get multiple variables and filter them
filter_var_array()
function obtains multiple variables and filters them.
Since filter_input()
is not required to be called repeatedly, this function is useful for filtering multiple variables.
If successful, return an array containing the filtered variable values, and if failed, false.
<?php $arr = array ( "name" => "peter griffin", "age" => "41", "email" => "[email protected]", ); $filters = array ( "name" => array ( "filter"=>FILTER_CALLBACK, "flags"=>FILTER_FORCE_ARRAY, "options"=>"ucwords" ), "age" => array ( "filter"=>FILTER_VALIDATE_INT, "options"=>array ( "min_range"=>1, "max_range"=>120 ) ), "email"=> FILTER_VALIDATE_EMAIL, ); print_r(filter_var_array($arr, $filters)); ?>
输出类似:
Array ( [name] => Peter Griffin [age] => 41 [email] => [email protected] )
filter_var_array ( array , args )
parameter | describe |
---|---|
array | Required. Specifies an array with string keys that contain the data to be filtered. |
args |
Optional. Specifies an array of filter parameters. The legal array key is the variable name. The legal value is the filter ID, or an array of specified filters, flags, and options. This parameter can also be a separate filter ID, if so, all values in the input array are filtered by the specified filter. |